package com.dy.cloud.controller;

import com.dy.cloud.pojo.Entity.PaymentEntity;
import com.dy.cloud.service.PaymentService;
import com.dy.cloud.util.ApiResousUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName:
 * @Author: 仄言in
 * @Desctiption: (描述)
 * @Date: 2021/9/2 17:15
 * @Version 1.0 (版本)
 */
@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {
    @Autowired
    private PaymentService paymentService;
    @Autowired
    private DiscoveryClient discoveryClient;
    @Value("${server.port}")
    private String port;

    /**
     * 正常访问
     * @return
     */
    @GetMapping("/ok/{id}")
    public ApiResousUtil payment_ok(@PathVariable("id") Integer id){
        return ApiResousUtil.ok(paymentService.payment_ok(id)+"port"+port);
    }

    /**
     * 延时访问
     * @return
     */
    @GetMapping("/timout/{id}")
    public ApiResousUtil payment_timout(@PathVariable("id") Integer id){
        return ApiResousUtil.ok(paymentService.payment_timout(id)+"port"+port);
    }
    /**
     * 全查询
     * @return ApiResousUtil
     **/
    @GetMapping("/list")
    public ApiResousUtil list(){
        List<PaymentEntity> list = paymentService.list(null);
        return ApiResousUtil.ok(list+"port"+port);
    }
    /**
     * 服务熔断
     * @param id
     * @return
     **/
    @GetMapping("/breaker/{id}")
    public ApiResousUtil breaker(@PathVariable("id")Integer id){
        return ApiResousUtil.ok(paymentService.paymentCircuitBreaker(id));
    }
}
